#!/bin/sh
# -*- sh-indentation: 3 -*-
#
# genie-config a la ROOT's root-config
#

### GENIE config options:
. $GENIE/src/make/Make.config_no_paths

### GENIE libraries path (local build location):
libdir=$GENIE/lib

### perhaps "installed" and lib is not at the same level as src
if test ! -d ${libdir} ; then
  installpathline=`grep GENIE_INSTALLATION_PATH $GENIE/src/make/Make.config`
  installpathval=`echo $installpathline | cut -d= -f2`
  ### extracted string might be an env variable itself
  installpath=`eval echo $installpathval`
  if test -d ${installpath}/lib ; then
    libdir=${installpath}/lib
  fi
fi

### GENIE src top level directory:
srcdir=$GENIE/src

### GENIE libraries;
# Order is important for loadlibs.C - try to keep libraries before those their depend on.

# Libraries from GENIE/Generator/Framework
# (always present)
fmwk_libs=" -lGFwMsg -lGFwReg -lGFwAlg -lGFwInt -lGFwGHEP -lGFwNum -lGFwUtl -lGFwParDat -lGFwEG -lGFwNtp "

# Libraries from GENIE/Generator/Physics
# (standard)
phys_libs=" -lGPhXSIg -lGPhPDF -lGPhNuclSt -lGPhCmn -lGPhDcy -lGPhHadTransp -lGPhHadnz  -lGPhDeEx \
  -lGPhAMNGXS -lGPhAMNGEG -lGPhChmXS -lGPhCohXS -lGPhCohEG  -lGPhDISXS -lGPhDISEG \
  -lGPhDfrcXS -lGPhDfrcEG -lGPhGlwResXS -lGPhGlwResEG -lGPhIBDXS -lGPhIBDEG \
  -lGPhMNucXS -lGPhMNucEG -lGPhMEL -lGPhNuElXS -lGPhNuElEG \
  -lGPhQELXS -lGPhQELEG -lGPhResXS -lGPhResEG -lGPhStrXS -lGPhStrEG "
# (optional)
if test "$GOPT_ENABLE_NUCLEON_DECAY" = "YES"; then
  phys_libs="$phys_libs -lGPhNDcy "
fi
if test "$GOPT_ENABLE_NNBAR_OSCILLATION" = "YES"; then
  phys_libs="$phys_libs -lGPhNNBarOsc"
fi
if test "$GOPT_ENABLE_BOOSTED_DARK_MATTER" = "YES"; then
  phys_libs="$phys_libs -lGPhBDMXS -lGPhBDMEG"
fi
if test "$GOPT_ENABLE_NEUTRAL_HEAVY_LEPTON" = "YES"; then
  phys_libs="$phys_libs -lGPhNHL "
fi

# Libraries from GENIE/Generator/Tools
# (standard)
tool_libs=" "
# (optional)
if test "$GOPT_ENABLE_GEOM_DRIVERS" = "YES"; then
  tool_libs="$tool_libs -lGTlGeo "
fi
if test "$GOPT_ENABLE_FLUX_DRIVERS" = "YES"; then
  tool_libs="$tool_libs -lGTlFlx "
fi
if test "$GOPT_ENABLE_MASTERCLASS" = "YES"; then
  tool_libs="$tool_libs -lGTlMcls "
fi

# Assemble the final libs variable
libs="-L$libdir $fmwk_libs $phys_libs $tool_libs "

### Usage
usage="\
Usage: genie-config [--libs] [--libdir] [--topsrcdir] [--version]"

if test $# -eq 0; then
   echo "${usage}" 1>&2
   exit 1
fi

out=""

while test $# -gt 0; do
  case "$1" in
  -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  *)    optarg= ;;
  esac

  case $1 in
    --libs)
      ### GENIE libraries
      out="$out $libs"
      ;;
    --libdir)
      ### Output GENIE libdir
      out="$out $libdir"
      ;;
    --topsrcdir)
      ### Output GENIE top level src directory
      out="$out $srcdir"
      ;;
    --version)
      ### Output version
      out="$out $(cat ${GENIE}/VERSION)"
      ;;
  esac
  shift
done

echo $out
